component	
	persistent	= true
	accessors	= true
	table		= 'Entry'
	extends		= 'model.BaseBean'
	entityname	= 'EntryBean'
	name		= 'EntryBean'
{
	property name='EntryID'			ormtype='integer' 	column='EntryID' fieldtype='id' generator='increment';
	property name='CreationDate'	ormtype='date';
	property name='Content'			ormtype='clob';
	property name='IsCommentable'	ormtype='boolean' 	default=true;
	property name='IsPublished'		ormtype='boolean'	default=false;
	property name='Title'			ormtype='string'	length='100';
	property name='SubTitle'		ormtype='string'	length='100';
	property name='Abstract'		ormtype='string'	length='500';
	property name='NbViews'			ormtype='integer' 	length='11' default=0;
	property name='NbComments'		ormtype='integer' 	length='11'	default=0;
	
	// Relationships
	property 
		name='Categories'
		fieldtype='many-to-many'
		cfc='model.blog.category.CategoryBean'
		linktable='CategoryHasEntry'
		fkcolumn='EntryID'
		inversejoincolumn='CategoryID'
		lazy='true';
	
	property 
		name='User'
		fieldtype='many-to-one'
		cfc='model.user.UserBean'
		fkcolumn='UserID';

	property 
		name='Type'
		fieldtype='many-to-one'
		cfc='model.blog.type.TypeBean'
		fkcolumn='TypeID';
				
	property 
		name='Comments'
		fieldtype='one-to-many'
		cfc='model.blog.comment.CommentBean'
		cascade='all'
		fkcolumn='EntryID';
		
	public function save() {
		updateNbComments();
		super.save();
	}
	public function delete() {
		updateNbComments();
		super.delete();
	}
	private function updateNbComments() {
		setNbComments( arrayLen( getComments() ) );
	}
}
